package com.tianqu.tms.www.car.controller;

import java.util.List;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsController;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.exception.TransactionException;
import com.tianqu.tms.dto.CarStyleCountDto;
import com.tianqu.tms.entity.Vendor;
import com.tianqu.tms.www.car.viewhelper.CarInformationShowViewHelper;

public class CarInformationShowController extends TmsController {
	private Logger logger = Logger.getLogger(CarInformationShowController.class);

	@Override
	public void execute(UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		TxController controller = TxController.getTxController();
		// 添加事务提交异常捕获
		try {
			CarInformationShowViewHelper viewhelper = new CarInformationShowViewHelper();
			controller.begin();
			viewhelper.setVendorDtolist(Vendor.getInstance().findAllVendorInfoCount());
			viewhelper.setTotal(Vendor.getInstance().findAllVendorInfoCountTotal());
			uc.setAttribute("titles", viewhelper);
			controller.commit();
		} catch (Exception e) {
			try {
				controller.rollback();
			} catch (TransactionException e1) {
				throw new TmsException(TmsException.DB_TXCRROR, e1);
			}
			// 系统异常
			if (e instanceof TmsException) {
				throw e;
			}
			throw new TmsException(TmsException.DB_TXCRROR, e);
		}

		logger.debug(this.getClass().getName() + "#execute was completed.");
	}
	
	public void execute(UserContext uc,String vendorId) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.vendorId:"+vendorId);
		TxController controller = TxController.getTxController();
		// 添加事务提交异常捕获
		try {
			CarInformationShowViewHelper viewhelper = new CarInformationShowViewHelper();
			controller.begin();
			List<CarStyleCountDto> list = Vendor.getInstance().getCarStyleCount(vendorId);
			viewhelper.setCarStyleCountDtoList(list);
			uc.setAttribute("tableData", viewhelper);
			controller.commit();
		} catch (Exception e) {
			try {
				controller.rollback();
			} catch (TransactionException e1) {
				throw new TmsException(TmsException.DB_TXCRROR, e1);
			}
			// 系统异常
			if (e instanceof TmsException) {
				throw e;
			}
			throw new TmsException(TmsException.DB_TXCRROR, e);
		}

		logger.debug(this.getClass().getName() + "#execute was completed.");
	
	}
}
